package com.cloud.edu.bus.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.edu.admin.request.demo.DemoRequest;
import com.cloud.edu.bus.client.admin.AdminClient;
//import com.cloud.edu.bus.service.DemoService;
import com.cloud.edu.cache.RedisHelper;
import com.cloud.edu.frm.BaseController;
import com.cloud.edu.model.response.ObjectDataResponse;
//import com.cloud.edu.sys.model.User;
//import com.cloud.edu.sys.model.demo.Demo;
import com.cloud.edu.utils.JsonDateValueProcessor;
import com.cloud.edu.utils.JsonUtils;
import com.cloud.edu.utils.PageUtils;



@Controller
@RequestMapping("/admin/demo")
@Api(value = "DemoController", description="测试接口")
public class DemoController extends BaseController{
	
//	@Resource(name="demoService1")  
//	private DemoService deomService;
//	
//	@Autowired
//	private RedisHelper redisHelper;
//	
//	@Autowired
//	private AdminClient adminClient;
//	
//    /**
//	 * 搜索页面信息
//	 * @param Page,request,response
//	 * @return JSON
//	 * @throws ServletException,IOException
//	 */
//	@ApiOperation(value = "查询列表", notes = "查询列表信息")
//    @RequestMapping(value = "query", method = RequestMethod.GET)
//    public void query (HttpServletRequest request, HttpServletResponse response) throws Exception{
//    	//获取分页、查询参数，进行数据封装
//		Demo demo=new Demo();
//		String sessionId=request.getSession().getId();
//    	//将用户登陆信息保存到数据库
//		Session session = SecurityUtils.getSubject().getSession();
//		String a=(String)session.getAttribute("userSessionId");
//		PageUtils pageUtils=new PageUtils();
//    	Map<?, ?> searchMap = deomService.getDemoPage(demo, pageUtils);
//    	super.responsePrint(request, response, JsonUtils.mapToJson(searchMap));
//    }
//    
//    /**
//     * 编辑页面初始化
//     * @param request,response
//	 * @return ModelAndView
//	 * @throws ServletException,IOException
//     */
//	@ApiOperation(value = "查询明细", notes = "查询明细信息")
//    @RequestMapping(value = "edit", method = RequestMethod.POST)
//    public void edit (@PathVariable("id") String id,HttpServletRequest request, HttpServletResponse response ) throws Exception{
//    	JSONObject returnObj = new JSONObject();
////		String id = request.getParameter("id");
//		if(id != null && !id.equals("")){
//			Demo Demo = deomService.getDemoByID(id);
////			JSONObject jsonObject = JSONObject.fromObject( Demo ); 
//			JsonConfig jsonConfig = new JsonConfig();    
//		    jsonConfig.registerJsonValueProcessor(Date.class , new JsonDateValueProcessor());  
//		    JSONObject Demojson = JSONObject.fromObject( Demo,jsonConfig );
//			
//			returnObj.element("data", Demojson);//成功
//		}
//		returnObj.element("httpCode", "OK");//成功
//		super.responsePrint(request, response, returnObj.toString());
//    }
//    
//    /**
//     * 保存数据信息
//     * @param Demo,request,response
//	 * @throws ServletException,IOException
//     */
//	@ApiOperation(value = "保存明细", notes = "保存明细信息")
//    @RequestMapping(value = "save", method = RequestMethod.POST)
//    public Object save (@Valid @RequestBody DemoRequest demoRequest,HttpServletRequest request, HttpServletResponse response ) throws Exception{
//    	String params=request.getParameter("data");
////    	JSONObject jsonObject = JSONObject.fromObject(params);
//    	Demo demo  = new Demo();    
//    	if(demo !=null && demo.getId()!=null && !demo.getId().equals("")){
//			//修改
//			deomService.updateDemo(demo);
//		}else{
//			//新增
//			//Demo.setCreateTime(new Date());
//			deomService.addDemo(demo);
//		}
//		ModelMap modelMap=new ModelMap();
//		modelMap.put("httpCode", "OK");
//		modelMap.put("timestamp", System.currentTimeMillis());
//		return ResponseEntity.ok(modelMap);
//    }
//    
//    /**
//     * 删除数据信息
//     * @param Demo,request,response
//	 * @return JSON
//	 * @throws ServletException,IOException
//	 */
//	@ApiOperation(value = "删除", notes = "删除数据信息")
//    @RequestMapping(value = "delete/{id}", method = RequestMethod.GET)
//	@ApiParam(required = true, name = "id", value = "唯一标识")
//    public void delete (@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws Exception{
//    	JSONObject returnObj = new JSONObject();
//    	//将用户登陆信息保存到数据库
//		Session session = SecurityUtils.getSubject().getSession();
////		String a=(String)session.getAttribute("userSessionId");
////    	request.getSession().setAttribute("user", id);
//    	redisHelper.set("qqq", "111111");
//    	deomService.deleteDemo(id);
//		returnObj.element("httpCode", "OK");//成功
//		String aaa=(String) redisHelper.get("qqq");
////		returnObj.element("id", id);//成功
//		super.responsePrint(request, response, returnObj.toString());
//    }
//	
//	
//
//	/**
//	 * 修改密码
//	 * @param old_pwd
//	 * @param new_pwd
//	 * @param session
//	 */
//	@PostMapping(value = "/setInfo", produces = "application/json;charset=UTF-8")
//	@ResponseBody
//	@ApiOperation(value = "修改密码", notes = "")
//	@ApiImplicitParams({
//		@ApiImplicitParam(name = "old_pwd", value ="旧密码", required = true, dataType = "String"),
//	})
//	public String setInfo(@RequestBody String new_pwd){
//		System.out.print("llll");
//		return null;
//	}
}


